package com.leyou.item.service;

import com.leyou.enums.ExceptionEnum;
import com.leyou.exception.LyException;
import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;


/**
 * 商品实现类
 */
@Service
public class CategoryService {
    @Autowired
    public CategoryMapper categoryMapper;

    /**
     * 查询商品分类
     * @param pid 根据parentId查询
     * @return
     */
    public List<Category> queryCategoryByListPid(Long pid){
        Category t =new Category();
        t.setParentId(pid);
        return this.categoryMapper.select(t);
    }

    /**
     * 查询商品三级分类
     * @param ids
     * @return
     */
    public List<Category> queryByIds(List<Long> ids) {
        final List<Category> list = categoryMapper.selectByIdList(ids);
        if (CollectionUtils.isEmpty(list)) {
            throw new LyException(ExceptionEnum.CATEGORY_NOT_FOUND);
        }
        return list;
    }

}
